cmake_minimum_required(VERSION 3.29)
project(common)

# 设置依赖
set(CONFIG_DEPENDS
  "rclcpp"
  "yaml-cpp"
  "ament_index_cpp"
)

set(MATH_DEPENDS
  "rclcpp"
  "main_interfaces"
  "geometry_msgs"
  "nav_msgs"
)

# 添加动态库
add_library(config_reader SHARED
  ${CMAKE_CURRENT_SOURCE_DIR}/config_reader/config_reader.cpp
)

add_library(mathlibs SHARED
  ${CMAKE_CURRENT_SOURCE_DIR}/math/curve.cpp
  ${CMAKE_CURRENT_SOURCE_DIR}/math/polynomial.cpp
)

# 设置目标名称
set(config_target
  config_reader
)

set(math_target
  mathlibs
)

# 让动态库关联上依赖
ament_target_dependencies(${config_target}
  ${CONFIG_DEPENDS}
)

ament_target_dependencies(${math_target}
  ${MATH_DEPENDS}
)

# 让动态库关联 第三方库
target_link_libraries(${config_target}
  yaml-cpp
)

target_link_libraries(${math_target}
  Eigen3::Eigen
)

# 安装动态库、节点和相关目录，动态库的目录需要添加到环境变量
install(TARGETS
  ${config_target}
  ${math_target}
  LIBRARY DESTINATION lib
)

